<?php
//	Public function

//	Private function

class	lg_string
{
//	Public function
	public static function	crop($text,$qty)
	{
		$txt			=	$text;
		$arr_replace	=	array("<p>","</p>","<br>","<br />","  ");
		$text			=	str_replace($arr_replace,"",$text);
		$dem			=	0;
		for ( $i=0 ; $i < strlen($text) ; $i++ )
		{
			if ($text[$i] == ' ') $dem++;
			if ($dem == $qty)	break;
		}
		$text		=	substr($text,0,$i);
		if ($i	<	strlen($txt))
			$text .= " ...";
		return	$text;
	}
	public static function	cut($text,$qty)
	{
		$txt			=	$text;
		return	substr($text,0,$qty).($qty<strlen($txt)?" ...":"");
	}
	
	public static function	escape($text)
	{
		return mysql_escape_string($text);
	}
	public static function	check_email($txt_email)
	{
		return (ereg("[A-Za-z0-9_-]+([\.]{1}[A-Za-z0-9_-]+)*@[A-Za-z0-9-]+([\.]{1}[A-Za-z0-9-]+)+", $txt_email));
	}
	
	public static function	analyse_url($url)
	{
		$qr	=	stristr($url,"?");
		$qr	=	trim($qr,"?");
		$x	=	explode("&",$qr);
		for ($i = 0; $i <= count($x); $i++)
		{
			if ($x[$i] != "")
			{
				$y = explode("=",$x[$i]);
				$arr[$y[0]] = $y[1];
			}
		}
		return $arr;
	}
	
	public static function	get_link($txt)
	{
		$text	=	self::UNI_2_TXT($txt);
		$text	=	strtolower($text);
		$text	=	str_replace(" ","-",$text);
		$src	=	array ( "?", "." , "," , "\"", "'", ":", "%", "/", "&");
		for ($i = 0; $i < count($src); $i++)
			$text	=	str_replace($src[$i],"",$text);
		return $text."/thai-thinh-nam.html";
	}
	public static function	bo_dau($txt)
	{
		return self::UNI_2_TXT($txt);
	}
//	Private function
	public static function	UNI_2_TXT ( $text )
	{
		$UNI	= array ( "á","à","ả","ã","ạ","ắ","ằ","ẳ","ẵ","ặ","ấ","ầ","ẩ","ẫ","ậ","é","è","ẻ","ẽ","ẹ","ế","ề","ể","ễ","ệ","í","ì","ỉ","ĩ","ị","ó","ò","ỏ","õ","ọ","ố","ồ","ổ","ỗ","ộ","ớ","ờ","ở","ỡ","ợ","ú","ù","ủ","ũ","ụ","ứ","ừ","ử","ữ","ự","ý","ỳ","ỷ","ỹ","ỵ","Á","À","Ả","Ã","Ạ","Ắ","Ằ","Ẳ","Ẵ","Ặ","Ấ","Ầ","Ẩ","Ẫ","Ậ","É","È","Ẻ","Ẽ","Ẹ","Ế","Ề","Ể","Ễ","Ệ","Í","Ì","Ỉ","Ĩ","Ị","Ó","Ỏ","Õ","Ọ","Ố","Ồ","Ổ","Ỗ","Ộ","Ơ","Ớ","Ờ","Ở","Ỡ","Ợ","Ú","Ù","Ủ","Ũ","Ụ","Ứ","Ừ","Ử","Ữ","Ự","Ý","Ỳ","Ỷ","Ỹ","Ỵ","ă","â","ê","ô","ơ","ư","đ","Ă","Â","Ê","Ô","Ò","Ư","Đ");
		$TXT	= array ( "a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","e","e","e","e","e","e","e","e","e","e","i","i","i","i","i","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","u","u","u","u","u","u","u","u","u","u","y","y","y","y","y","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","E","E","E","E","E","E","E","E","E","E","I","I","I","I","I","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","U","U","U","U","U","U","U","U","U","U","Y","Y","Y","Y","Y","a","a","e","o","o","u","d","A","A","E","O","O","U","D");
	
		for ($i = 0; $i < count($UNI); $i++)
		{
			$text = str_replace($UNI[$i], $TXT[$i], $text);
		}
		return $text;
	}
	public static function	UNI_2_TCVN3 ( $text )
	{
		$UNI	= array ( "à", "á", "ả", "ã", "ạ", "ă", "ằ", "ắ", "ẳ", "ẵ", "ặ", "â", "ầ", "ấ", "ẩ", "ẫ", "ậ", "đ", "è", "é", "ẻ", "ẽ", "ẹ", "ê", "ề", "ế", "ể", "ễ", "ệ", "ì", "í", "ỉ", "ĩ", "ị", "ò", "ó", "ỏ", "õ", "ọ", "ô", "ồ", "ố", "ổ", "ỗ", "ộ", "ơ", "ờ", "ớ", "ở", "ỡ", "ợ", "ù", "ú", "ủ", "ũ", "ụ", "ư", "ừ", "ứ", "ử", "ữ", "ự", "ỳ", "ý", "ỷ", "ỹ", "ỵ", "Ă", "Â", "Đ", "Ê", "Ô", "Ơ", "Ư");
		$TCVN3	= array ( "µ", "¸", "¶", "·", "¹","¨", "»", "¾", "¼", "½", "Æ","©", "Ç", "Ê", "È", "É", "Ë","®", "Ì", "Ð", "Î", "Ï", "Ñ","ª", "Ò", "Õ", "Ó", "Ô", "Ö","×","Ý", "Ø", "Ü", "Þ","ß", "ã", "á", "â", "ä","«", "å", "è", "æ", "ç", "é","¬", "ê", "í", "ë", "ì", "î", "ï", "ó", "ñ", "ò", "ô", "­", "õ", "ø", "ö", "÷", "ù","ú", "ý", "û", "ü", "þ", "¡", "¢", "§", "£", "¤", "¥", "¦");
	
		for ($i = 0; $i < count($UNI); $i++)
		{
			$text = str_replace($UNI[$i], $TCVN3[$i], $text);
		}
		return $text;
	}
	public static function u2v ( $text2 )
	{
		$text = utf8_encode($text2);
		$UNI	= array ("Ã","Ã ","Ã","Ã¡","Ã","Ã¢","Ã","Ã£","Ã","Ã¨","Ã","Ã©","Ã","Ãª","Ã","Ã¬","Ã","Ã­","Ã","Ã²","Ã","Ã³","Ã","Ã´","Ã","Ãµ","Ã","Ã¹","Ã","Ãº","Ã","Ã½","Ä","Ä","Ä","Ä","Ä¨","Ä©","Å¨","Å©","Æ ","Æ¡","Æ¯","Æ°","áº ","áº¡","áº¢","áº£","áº¤","áº¥","áº¦","áº§","áº¨","áº©","áºª","áº«","áº¬","áº­","áº®","áº¯","áº°","áº±","áº²","áº³","áº´","áºµ","áº¶","áº·","áº¸","áº¹","áºº","áº»","áº¼","áº½","áº¾","áº¿","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á»","á» ","á»¡","á»¢","á»£","á»¤","á»¥","á»¦","á»§","á»¨","á»©","á»ª","á»«","á»¬","á»­","á»®","á»¯","á»°","á»±","á»²","á»³","á»´","á»µ","á»¶","á»·","á»¸","á»¹");
		$VNI	= array ("AØ","aø","AÙ","aù","AÂ","aâ","AÕ","aõ","EØ","eø","EÙ","eù","EÂ","eâ","Ì","ì","Í","í","OØ","oø","OÙ","où","OÂ","oâ","OÕ","oõ","UØ","uø","UÙ","uù","YÙ","yù","AÊ","aê","Ñ","ñ","Ó","ó","UÕ","uõ","Ô","ô","Ö","ö","AÏ","aï","AÛ","aû","AÁ","aá","AÀ","aà","AÅ","aå","AÃ","aã","AÄ","aä","AÉ","aé","AÈ","aè","AÚ","aú","AÜ","aü","AË","aë","EÏ","eï","EÛ","eû","EÕ","eõ","EÁ","eá","EÀ","eà","EÅ","eå","EÃ","eã","EÄ","eä","Æ","æ","Ò","ò","OÏ","oï","OÛ","oû","OÁ","oá","OÀ","oà","OÅ","oå","OÃ","oã","OÄ","oä","ÔÙ","ôù","ÔØ","ôø","ÔÛ","ôû","ÔÕ","ôõ","ÔÏ","ôï","UÏ","uï","UÛ","uû","ÖÙ","öù","ÖØ","öø","ÖÛ","öû","ÖÕ","öõ","ÖÏ","öï","YØ","yø","Î","î","YÛ","yû","YÕ","yõ");
	
		for ($i = 0; $i < count($UNI); $i++)
		{
			$text = str_replace($UNI[$i], $VNI[$i], $text);
		}
		return $text;
	}
	private	$VIQR_char = array(
		"y~", "Y~", "y?", "Y?", "y.", "Y.", "y`", "Y`", "u+.", "U+.", "u+~",
		"U+~", "u+?", "U+?", "u+`", "U+`", "u+'", "U+'", "u?", "U?", "u.", "U.", "o+.", "O+.",
		"o+~", "O+~", "o+?", "O+?", "o+`", "O+`", "o+'", "O+'", "o^.", "O^.", "o^~", "O^~", "o^?",
		"O^?", "o^`", "O^`", "o^'", "O^'", "o?", "O?", "o.", "O.", "i.", "I.", "i?", "I?", "e^.",
		"E^.", "e^~", "E^~", "e^?", "E^?", "e^`", "E^`", "e^'", "E^'", "e~", "E~", "e?", "E?", "e.",
		"E.", "a(.", "A(.", "a(~", "A(~", "a(?", "A(?", "a(`", "A(`", "a('", "A('", "a^.", "A^.",
		"a^~", "A^~", "a^?", "A^?", "a^`", "A^`", "a^'", "A^'", "a?", "A?", "a.", "A.", "u+", "U+",
		"o+", "O+", "u~", "U~", "i~", "I~", "dd", "a(", "A(", "y'", "u'", "u`", "o~", "o^", "o'",
		"o`", "i'", "i`", "e^", "e'", "e`", "a~", "a^", "a'", "a`", "Y'", "U'", "U`", "O~", "O^",
		"O'", "O`", "DD", "I'", "I`", "E^", "E'", "E`", "A~", "A^", "A'", "A`");
	private	$Unicode_char = array(
		"\u1EF9", "\u1EF8", "\u1EF7", "\u1EF6", "\u1EF5", "\u1EF4",
		"\u1EF3", "\u1EF2", "\u1EF1", "\u1EF0", "\u1EEF", "\u1EEE", "\u1EED", "\u1EEC", "\u1EEB",
		"\u1EEA", "\u1EE9", "\u1EE8", "\u1EE7", "\u1EE6", "\u1EE5", "\u1EE4", "\u1EE3", "\u1EE2",
		"\u1EE1", "\u1EE0", "\u1EDF", "\u1EDE", "\u1EDD", "\u1EDC", "\u1EDB", "\u1EDA", "\u1ED9",
		"\u1ED8", "\u1ED7", "\u1ED6", "\u1ED5", "\u1ED4", "\u1ED3", "\u1ED2", "\u1ED1", "\u1ED0",
		"\u1ECF", "\u1ECE", "\u1ECD", "\u1ECC", "\u1ECB", "\u1ECA", "\u1EC9", "\u1EC8", "\u1EC7",
		"\u1EC6", "\u1EC5", "\u1EC4", "\u1EC3", "\u1EC2", "\u1EC1", "\u1EC0", "\u1EBF", "\u1EBE",
		"\u1EBD", "\u1EBC", "\u1EBB", "\u1EBA", "\u1EB9", "\u1EB8", "\u1EB7", "\u1EB6", "\u1EB5",
		"\u1EB4", "\u1EB3", "\u1EB2", "\u1EB1", "\u1EB0", "\u1EAF", "\u1EAE", "\u1EAD", "\u1EAC",
		"\u1EAB", "\u1EAA", "\u1EA9", "\u1EA8", "\u1EA7", "\u1EA6", "\u1EA5", "\u1EA4", "\u1EA3",
		"\u1EA2", "\u1EA1", "\u1EA0", "\u01B0", "\u01AF", "\u01A1", "\u01A0", "\u0169", "\u0168",
		"\u0129", "\u0128", "\u0111", "\u0103", "\u0102", "\u00FD", "\u00FA", "\u00F9", "\u00F5",
		"\u00F4", "\u00F3", "\u00F2", "\u00ED", "\u00EC", "\u00EA", "\u00E9", "\u00E8", "\u00E3",
		"\u00E2", "\u00E1", "\u00E0", "\u00DD", "\u00DA", "\u00D9", "\u00D5", "\u00D4", "\u00D3",
		"\u00D2", "\u0110", "\u00CD", "\u00CC", "\u00CA", "\u00C9", "\u00C8", "\u00C3", "\u00C2",
		"\u00C1", "\u00C0");
}
?>